﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MyPoints
{
  /// <summary>
  /// Interaction logic for AboutWindow.xaml
  /// </summary>
  public partial class AboutWindow : Window
  {
    public class Thank
    {
      public string Text { get; set; }
      public string Url { get; set; }

      public Thank(string url)
      {
        this.Text = url;
        this.Url = url;
      }
      public Thank(string text, string url)
      {
        this.Text = text;
        this.Url = url;
      }
    }

    public class AboutWindowVM
    {
      public string Title { get; set; }
      public string Url { get; set; }
      public string Version { get; set; }

      public string Description { get; set; }

      public string Author { get; set; }
      public string MailTo { get; set; }
      public string Mail { get; set; }

      public string Copyright { get; set; }
      public string Company { get; set; }
      public List<Thank> Thanks { get; set; }

      public AboutWindowVM()
      {
        Assembly app = Assembly.GetExecutingAssembly();

        var t = (AssemblyTitleAttribute)app.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];
        this.Title = t.Title;

        var p = (AssemblyProductAttribute)app.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0];
        this.Author = "... by " + p.Product;

        this.Mail = "engin@seznam.cz";
        this.MailTo = "mailto:" + this.Mail;

        var co = (AssemblyCopyrightAttribute)app.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0];
        this.Copyright = co.Copyright;

        var cm = (AssemblyCompanyAttribute)app.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0];
        this.Company = cm.Company;

        var d = (AssemblyDescriptionAttribute)app.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)[0];
        this.Description = d.Description;

        this.Version = "Ver.: " + app.GetName().Version.ToString();

        this.Url = "http://mypoints.codeplex.com";

        this.Thanks = new List<Thank>();
        Thanks.Add(
          new Thank(
            "Christian Mosers WPF tutorial", 
            "http://www.wpftutorial.net/"));

        Thanks.Add(
          new Thank(
          "Great Maps for Windows", 
          "https://greatmaps.codeplex.com/"));

        Thanks.Add(
          new Thank(
            "Hopstarters for \"soft scraps\" icon set", 
            "http://www.iconarchive.com/show/soft-scraps-icons-by-hopstarter.1.html"));

        Thanks.Add(
          new Thank(
            "Icon-Land for \"Vista map markers\" icon set ",
            "http://www.icons-land.com")); // http://www.iconarchive.com/show/vista-map-markers-icons-by-icons-land.html");

      }


    }

    private AboutWindowVM vm = new AboutWindowVM();

    public AboutWindow()
    {
      InitializeComponent();
      this.DataContext = vm;
    }

    private void btnOk_Click(object sender, RoutedEventArgs e)
    {
      this.Close();
    }
  }
}
